<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2019/2/15
  Time: 15:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$Title$</title>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<div  align="center">
    <a href="#" onclick="userlike()" class="js-like" name="userlike" id="like" value="3">收藏</a>
</div>

</body>
<script text="text/javascript">
    function userlike(){
        //获取收藏对象的ID
        var likeId = $("#like").attr("value");
        //获取用户ID
        var userId = 1001;
        //获取收藏类型ID
        var likeType = 2;
        $.ajax({
            "url":<%=request.getContextPath()%>"/UserLikeServlet",
            "data":"likeId="+likeId+"&userId="+userId+"&likeType="+likeType,
            "type": "GET",
            "dataType":"json",
            "success": function (result){
                if(result.data== "YES"){
                    alert("收藏成功");
                } else if(result.data == "NO"){
                    alert("取消收藏成功");
                }else{
                    alert("操作异常，请稍后重试");
                }
            }
        })
    }
</script>
</html>
